<template>
    <div>
        <P v-for="i in paramslist" :key="i.id">
            <van-field v-if="i.type == 'input'" :label="i.lable" type="datetime" v-model="values[i.lable]"/>
            <select v-if="i.type == 'select'"  v-model="values[i.lable]">
                <option :value="o.type" v-for="o in i.values" :key="o.id">{{o.name}}</option>
            </select>
            <van-uploader v-if="i.type == 'file'"/>
            <el-date-picker v-if="i.type == 'datetime'"
                v-model="value1"
                type="datetimerange"
                range-separator="To"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                >
            </el-date-picker>
        </P>
        <van-button @click="submit">提交</van-button>
    </div>
</template>

<script>
import maxios from '../http/axios'
export default {
    data() {
        return {
            wid:this.$route.query.id,
            workf:{},
            paramslist:[],
            value1:[],
            values:{},
            pic:'../assets/logo32x32.png',
        }
    },
    methods: {
        getwork(){
            maxios('getworkf','get',{'id':this.wid}).then(res => {
                this.workf = res.workf
                this.paramslist = JSON.parse(res.workf.params)
            })
        },
        getlabelByType(type){
            let label='' // eslint-disable-line no-unused-vars
            for(var i=0;i<this.paramslist.length;i++){
                if(this.paramslist[i]['type'] == type){
                    label = this.parselist[i]['lable']
                }
            }
        },
        submit(){
            if(this.pic){
                let label = this.getlabelByType('file')
                this.values[label] = this.pic
            }
            if(this.value1.length>0){
                let stime = this.getlabelByType('datetime')
                this.values[stime] = this.value1[0]
                this.values['结束时间'] = this.value1[0]
            }
            console.log(this.values)
        },
        
    },
    created() {
        this.getwork()
        this.getlabelByType()
    }
}
</script>

<style scoped>

</style>
